package com.magold.physics.magnetic;

import com.badlogic.gdx.math.Vector2;

public class MonoDirectionSolver implements DirectionSolver {
	private Monopole mMonopole;
	private Vector2 mDirectionBuf;
	
	public MonoDirectionSolver(Monopole pMonopole) {
		mMonopole = pMonopole;
		mDirectionBuf = new Vector2();
	}

	@Override
	public Vector2 computeDirection(MagneticPole pPole, float pX, float pY) {
		mDirectionBuf.set(pX, pY);
		float[] source = mMonopole.getMagneticSourcePosition();
		mDirectionBuf.sub(source[0], source[1]);
		
		if (pPole == mMonopole.getPole()) {
			mDirectionBuf.mul(-1);
		}
		
		return mDirectionBuf.nor();
	}
}
